﻿using Newtonsoft.Json;

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace JmShared
{
    
    public class UserInfo : IEquatable<UserInfo>
    {
        #region Properties
        [JsonIgnore]
        public string UserID
        {
            get { return UserName + "#" + ID; }
        }
        /// <summary>
        /// Get nickname if available, else returns username
        /// </summary>
        /// <returns></returns>
        [JsonIgnore]
        public string PrettyName
        {
            get
            {
                return String.IsNullOrEmpty(this.NickName) ? this.UserName : this.NickName;
            }
        }

        [UserInfoAttribute(UserInfoAttributeType.Nickname)]
        
        public string NickName { get; set; }

        
        public string UserName { get; set; }

        [UserInfoAttribute(UserInfoAttributeType.FontFamily)]
        
        public string FontFamily { get; set; }

        [UserInfoAttribute(UserInfoAttributeType.FontWeight)]
        
        public string FontWeight { get; set; }

        [UserInfoAttribute(UserInfoAttributeType.FontStyle)]
        
        public string FontStyle { get; set; }

        [UserInfoAttribute(UserInfoAttributeType.FontColor)]
        
        public string Color { get; set; }

        /// <summary>
        /// Unique identifier of the decice running the client.
        /// </summary>
        public string ID { get; set; }

        
        public ClientStatus? ClientStatus { get; set; }

        
        public DateTimeOffset? TimestampAfk { get; set; }
        
        public DateTimeOffset? TimestampOffline { get; set; }

        
        public string ClientVersion { get; set; }

        [UserInfoAttribute(UserInfoAttributeType.ChatGroups)]
        
        public IList<ChatGroup> ChatGroups { get; set; }


        //[UserInfoAttribute(UserInfoAttributeType.Avatar)]
        
        //public byte[] Avatar { get; set; }

        [UserInfoAttribute(UserInfoAttributeType.Avatar)]
        public Avatar Avatar { get; set; }

        [UserInfoAttribute(UserInfoAttributeType.CustomEmoticons)]
        public HashSet<ContactEmoticon> CustomEmoticons { get; set; }
       // public Dictionary<string, string> CustomEmoticons { get; set; }

        #endregion

        public UserInfo(string username, string deviceID)
        {
            this.UserName = username;
            this.ID = deviceID;
        }
        public UserInfo() { }

        public override string ToString()
        {
            return UserName;
        }
        public override int GetHashCode()
        {
            return this.UserID.GetHashCode();
        }
        public override bool Equals(object obj)
        {
            return Equals(obj as UserInfo);
        }
        public bool Equals(UserInfo other)
        {
            if (other == null)
                return false;
            return this.UserID == other.UserID;
        }

        public UserInfo Clone()
        {
            return (UserInfo)this.MemberwiseClone();
        }
    }
}
